package com.oldbook.manage.controller;

import com.oldbook.common.annotation.Log;
import com.oldbook.common.core.controller.BaseController;
import com.oldbook.common.core.domain.AjaxResult;
import com.oldbook.common.core.page.TableDataInfo;
import com.oldbook.common.enums.BusinessType;
import com.oldbook.common.utils.poi.ExcelUtil;
import com.oldbook.manage.domain.SensitiveWords;
import com.oldbook.manage.service.ISensitiveWordsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
 * 敏感词管理Controller
 *
 * @author Exiaoke
 * @date 2025-02-27
 */
@RestController
@RequestMapping("/manage/words")
@Api(tags = "敏感词管理管理")
public class SensitiveWordsController extends BaseController {

    @Autowired
    private ISensitiveWordsService sensitiveWordsService;

    /**
     * 查询敏感词管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:words:list')")
    @GetMapping("/list")
    @ApiOperation("查询敏感词管理列表")
    public TableDataInfo list(@ApiParam("敏感词管理对象") SensitiveWords sensitiveWords) {
        startPage();
        List<SensitiveWords> list = sensitiveWordsService.selectSensitiveWordsList();
        return getDataTable(list);
    }

    /**
     * 导出敏感词管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:words:export')")
    @Log(title = "敏感词管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出敏感词管理列表")
    public void export(HttpServletResponse response, @ApiParam("敏感词管理对象") SensitiveWords sensitiveWords) {
        List<SensitiveWords> list = sensitiveWordsService.selectSensitiveWordsList();
        ExcelUtil<SensitiveWords> util = new ExcelUtil<SensitiveWords>(SensitiveWords.class);
        util.exportExcel(response, list, "敏感词管理数据");
    }

    /**
     * 获取敏感词管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:words:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取敏感词管理详细信息")
    public AjaxResult getInfo(@PathVariable("id") @ApiParam("id的值") Long id) {
        return success(sensitiveWordsService.selectSensitiveWordsById(id));
    }

    /**
     * 新增敏感词管理
     */
    @PreAuthorize("@ss.hasPermi('manage:words:add')")
    @Log(title = "敏感词管理", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增敏感词管理")
    public AjaxResult add(@RequestBody @ApiParam("要添加的敏感词管理对象") SensitiveWords sensitiveWords) {
        return toAjax(sensitiveWordsService.insertSensitiveWords(sensitiveWords));
    }

    /**
     * 修改敏感词管理
     */
    @PreAuthorize("@ss.hasPermi('manage:words:edit')")
    @Log(title = "敏感词管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改敏感词管理")
    public AjaxResult edit(@RequestBody @ApiParam("要修改的敏感词管理对象") SensitiveWords sensitiveWords) {
        return toAjax(sensitiveWordsService.updateSensitiveWords(sensitiveWords));
    }

    /**
     * 删除敏感词管理
     */
    @PreAuthorize("@ss.hasPermi('manage:words:remove')")
    @Log(title = "敏感词管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除敏感词管理")
    public AjaxResult remove(@PathVariable @ApiParam("要删除的id数组") Long[] ids) {
        return toAjax(sensitiveWordsService.deleteSensitiveWordsByIds(ids));
    }
}